package controller;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Account;
import model.AccountDAO;
import model.AccountHome;
import model.DAOFactory;

import org.apache.jasper.tagplugins.jstl.core.Out;

/**
 * Servlet implementation class SignupProcess
 */
@WebServlet(description = "processing a request for creating a new account", urlPatterns = { "/SignupProcess" })
public class SignupProcess extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SignupProcess() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//	    doPost(request, response);
	}

	/**
	 * Process new account registration
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    PrintWriter out = response.getWriter();
	    Account newAccount = new Account();
	    
	    newAccount.setAccountName(request.getParameter("newUserName"));
	    newAccount.setPassword(request.getParameter("choosePassword"));
	    newAccount.setEmail(request.getParameter("uerEmail"));
	    newAccount.setRecoveryEmail(request.getParameter("userRecoveryEmail"));
	    newAccount.setFirstName(request.getParameter("userFirstName"));
	    newAccount.setMiddleName(request.getParameter("userMiddleName"));
	    newAccount.setLastName(request.getParameter("userLastName"));
	    newAccount.setLocation(request.getParameter("userLocation"));
	    
	    //Debug code
	    out.print(getServletContext().getRealPath("Account.hbm.xml"));
	    
	    
	    DAOFactory.getInstance().getAccountDAO().persist(newAccount);
//	    accountCreator.persist(newAccount);
	    
	}
	
	private boolean checkUserInfo(Account user){
	    return false;
	}

}
